package com.atguigu.gulimall.order.controller;

import com.atguigu.gulimall.order.entity.OrderEntity;
import com.atguigu.gulimall.order.entity.OrderReturnReasonEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.UUID;

@Slf4j
@RestController
public class TestController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/tests")
    public String test() {
        for (int i = 1; i < 11; i++) {
            if (i % 2 == 0) {
                OrderReturnReasonEntity entity = new OrderReturnReasonEntity();
                entity.setId(10L);
                entity.setCreateTime(new Date());
                // 如果发送的消息是个对象，我们会使用序列化机制将对象写出去，所以必须实现序列化接口
                // 自定义序列化机制

                rabbitTemplate.convertAndSend("hello-java-exchange","hello_java",entity);
                log.info("消息发送完成");
            }else{
                OrderEntity orderEntity = new OrderEntity();
                orderEntity.setDeliverySn(UUID.randomUUID().toString());
                // 如果发送的消息是个对象，我们会使用序列化机制将对象写出去，所以必须实现序列化接口
                // 自定义序列化机制

                rabbitTemplate.convertAndSend("hello-java-exchange","hello_java",orderEntity);
                log.info("消息发送完成");
            }
        }
        return "ok";
    }
}
